import type { IQuery, TableResponse } from '@/api/config/types';
import type { SelectProps } from 'ant-design-vue/es/vc-select';
import axios from 'axios';

const prefix = '/template/template';

export interface ITemplate {
  templateId?: string;
  templateName: string;
  resolutionId?: string;
  templateColor: string;
  templateData: null | any; // 根据实际情况改变类型
  imgSrc: string;
  scale: number;
  deptId: string;
  share: '0' | '1';
  resolution: {
    resolutionId: string;
    width: number;
    height: number;
    description: string;
    dpi: number;
    scale: number;
    toRotate: number;
  };
  resolutionDesc: string;
  resolutionWidth: number;
  resolutionHeight: number;
  templateList: Array<any>;
  /* 是否是主模板 */
  major: any;
  goodsList?: any[];
}
export type TemplateStatistics = {
  desc: string;
  options: SelectProps[];
  resolutionId: string;
  templateId: string;
};

export const listTemplate = (query?: IQuery) => {
  return axios.get<TableResponse<ITemplate>>(`${prefix}/list`, { params: query });
};

export const listMarket = (query?: IQuery) => {
  return axios.get<TableResponse<ITemplate>>(`${prefix}/market`, { params: query });
};

export const previewTpl = (data: any) => {
  return axios.post(`${prefix}/previewTpl`, data);
};

export const addTpl = (data: { stage: any; templateList: any[] }) => {
  return axios.post(`${prefix}/addTpl`, data);
};

export const getTemplate = (id: string) => {
  return axios.get(`${prefix}/${id}`);
};

export const saveTpl = (data: { stage: any; lcd: boolean }, immediately = false) => {
  return axios.post(`${prefix}/saveTpl`, data, {
    params: { immediately },
  });
};

export const updateTemplate = (data: ITemplate) => {
  return axios.put(`${prefix}`, data);
};

export const delTemplate = (id: string[]) => {
  return axios.delete(`${prefix}/${id.join(',')}`);
};
type CopyTemplate = {
  copyList: string[];
  rename: string;
};
export const copyTemplate = (data: CopyTemplate) => {
  return axios.post(`${prefix}/copy`, data);
};

export const refOptions = (id: string) => {
  return axios.get(`${prefix}/refOptions`, { params: { scope: 3, templateId: id } });
};

export const getBoundCount = (id: string) => {
  return axios.get(`${prefix}/getBoundCount`, { params: { templateId: id } });
};

export const templateQuery = (queryType?: 0) => {
  return axios.get(`${prefix}/query`, { params: { queryType } });
};
